/**
 * Created by own on 2017/12/5.
 */
//首页老师列表开始
$.ajax({
    url: url + 'getteachers?page=1',
    type: 'post',
    data: {},
    dataType: 'json',
    async: 'true',
    timeout: 2000,
    success: function (data) {
        if (data.code == '1000' && data.status == '1') {
            var indexLt = data.data;
            var html = '';
            $.each(indexLt, function (k, v) {
                this.xingbie == 1 ? this.xingbie = 'flag1' : this.xingbie = 'nflag1';
                this.isrenzheng == 1 ? this.isrenzheng = '<i class="flag2"></i>' : this.isrenzheng = '';

                html += '<li>'
                    + '<div class="te_left">'
                    + '<img src="' + this.headimage + '"/>'
                    + '</div>'
                    + '<div class="te_right">'
                    + '<h5><span>' + this.xingming + '</span><i class="' + this.xingbie + '"></i>' + this.isrenzheng
                    +'<button class="attention mui-pull-right"><a onclick="guanzhu('+this.id+')">关注</a></button>'
                    + '</h5>'
                    + '<p>' + this.hangdang + '</p>'
                    + '<div class="te_bottom">'
                    + '<button><a href="detail.html?id=' + this.id + '">立即预约</a></button>'
                    + '<p>'
                    + '<span class="color1">￥</span>'
                    + '<span class="color1 font16">' + this.price + '</span>'
                    + '<span class="color2">起</span>'
                    + '</p>'
                   +'</div>'
                    + '</div>'
                + '</li>';
                if (this.stdate != null && this.stdate != '') {
                    var week = '';
                    switch (this.week) {
                        case '1':
                            week = '周一';
                            break;
                        case '2':
                            week = '周二';
                            break;
                        case '3':
                            week = '周三';
                            break;
                        case '4':
                            week = '周四';
                            break;
                        case '5':
                            week = '周五';
                            break;
                        case '6':
                            week = '周六';
                            break;
                        case '7':
                            week = '周日';
                            break;
                    }
                    html += '<p class="mui-text-center">'
                        + '<b>预约时间:</b>'
                        + '日期：' + this.stdate + '/' + this.enddate + ' ' + week + '<br><b>时间段：</b>' + this.sttime + '/' + this.endtime
                        + '</p>';

                }



            });
            $('#teacher>div>ul').html(html);
        }
    },
    error: function () {
        mui.alert('数据加载失败', function () {
        });
    }
});
//关注
function guanzhu(id) {
    $.ajax({
        url: url + 'guanzhu',
        dataType: 'json',
        type: 'post',
        async: true,
        data: {
            'teachid': id
        },
        success: function (result) {
            // console.log(result);
            var status = result.status;
            var code = result.code;
            if (status == 1 && code == '1000') {
                mui.alert('关注成功', function () {
                });
            } else if (status == 1 && code == '1002') {
                mui.alert('未登录', function () {
                });
                // window.history.back();
            } else if (status == 1 && code == '1008') {
                mui.alert('已经关注过', function () {
                });
            }
        },
        error: function (result) {
            mui.alert(result, function () {
            });
            ;
        }
    })
}